/**
 * 作者: wgx
 * 日期: 2025-05-14 17:11:56
 * 备注: 玩家大世界行军的战报
 */
package com.motu.monstercity.server.game.userdata;

import com.motu.monstercity.server.game.base.AllParam;
import com.motu.monstercity.server.game.logic.FightManager;
import com.motu.monstercity.server.game.logic.WorldManager;
import com.motu.vertx.module.utility.model.EntityManager;
import com.motu.vertx.module.utility.redis.RedisTools;
import com.motu.vertx.module.utility.toolset.Tool;
import io.vertx.core.Future;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;

public class UserWorldRecord extends UserWorldRecordModel {
    public UserWorldRecord() {
        super();
    }

    public void doCreate() {
        setTableId();
        insert();
    }

    public JsonObject insert() {
        // 如果超过上限则会删除最早的那条
        long count = Future.await(RedisTools.getHashLen(getListKey()));
        if (count >= AllParam.WORLD_RECORD_MAX) {
            String orderListKey = EntityManager.getOrderListKey(getListKey());
            String delRecord = Future.await(RedisTools.lpop(orderListKey));// 删除列表数据
            long id = Long.parseLong(delRecord);// dbid
            UserWorldRecord record = WorldManager.getUserWorldRecord(getUserId(), id);
            if (record != null) {
                record.delete();
            }
        }
        return super.insert();
    }

    // 判断战报是否有奖励
    public boolean hasReward() {
        if (Tool.isEmpty(this.getReward())) {
            return false;
        }
        return true;
    }

    // 是否已领取奖励 已经领取过了
    public boolean isGet() {
        return getIsGetReward() == 1;
    }

}
